package cn.kgc.eduservice.controller.front;

import cn.kgc.commonutils.R;
import cn.kgc.eduservice.entity.EduCourse;
import cn.kgc.eduservice.entity.EduTeacher;
import cn.kgc.eduservice.service.EduCourseService;
import cn.kgc.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName TeacherFrontController
 * @Description: TODO
 * @Author :郭建宾
 * @Date 2020/7/16
 * @Version V1.0
 **/
@Api(tags="前台讲师")
@RestController
@RequestMapping("/eduservice/teacherfront")
//@CrossOrigin
public class TeacherFrontController {
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;
    //分页查询讲师的方法
    @ApiOperation("前台分页查询讲师")
    @PostMapping("getTeacherFronList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable Long page,@PathVariable Long limit){
        Page<EduTeacher> pageTeacher = new Page<>(page, limit);
        Map<String,Object> map = teacherService.getTeacherFrontList(pageTeacher);
        //返回分页所有数据
        return  R.ok().data(map);
    }
    //讲师详情的功能
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo (@PathVariable String teacherId){
        //根据讲师id 查询讲师基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);

        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }
}
